package com.angel.dtoutlis;

import com.angel.bean.Product;
import com.angel.bean.ProductType;
import com.angel.dto.EmployeeDto;
import com.angel.dto.ProductDto;
import com.github.pagehelper.Page;

import java.util.ArrayList;
import java.util.List;

public class ProductDtoUtil {

    /**
     * 将商品和商品类型进行封装
     *
     * @param productList
     * @param productTypeList
     * @return
     */
    public static Page<ProductDto> getProductDto(List<Product> productList, List<ProductType> productTypeList) {
        if (isNull(productList) || isNull(productTypeList)) {
            return null;
        }
        Page<ProductDto> dtoList = new Page<>();

        for (int i = 0; i < productList.size(); i++) {
            for (int j = 0; j < productTypeList.size(); j++) {
                if (productList.get(i).getProTypeId().equals(productTypeList.get(j).getProTypeId())) {
                    dtoList.add(new ProductDto(productList.get(i), productTypeList.get(j)));
                }
            }
        }

        return dtoList;
    }


    /**
     * 判断传入集合是否是空值
     *
     * @param list
     * @return
     */
    private static boolean isNull(List list) {
        if (list == null || list.isEmpty()) {
            return true;
        }
        return false;
    }
}
